package com.learn.im.factory;

import com.learn.im.enums.MsgType;
import com.learn.im.servcie.MessageHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author Emp
 * @version :    1.0
 */
@Component
public class MessageHandlerContext {

    private final Map<String, MessageHandler> handlerMap;

    @Autowired
    public MessageHandlerContext(Map<String, MessageHandler> handlers){
        handlerMap = handlers;
    }

    public MessageHandler createHandler(MsgType type){
        return handlerMap.get(type.name());
    }
}
